<?php

$db		= new Kegiatan();
$table 	= "kegiatan";
$table2 = "kabkota";
$table3 = "sektoral";
$table4 = "monitoring";
$id 	= htmlentities(mysql_real_escape_string($_GET['id']));
$order 	= "idkegiatan";

$kegiatan   = $db->lihat($table,$table2,$table3,$order,$id);
$image 		= $db->lihat_monitoring($table4, $id);
$colors 	= $db->lihat_progres($table4, $id);

if ($colors) {
	foreach ($colors as $progres) {
		
		if ($progres['maks'] <= 25) {
			$color = "#ff0000"; // red
		} elseif ($progres['maks'] <= 50) {
			$color = "#ff00ff"; // purple
		} elseif ($progres['maks'] <= 75) {
			$color = "#ff6600"; // orange
		} elseif ($progres['maks'] <= 100) {
			$color = "#00FF00"; // green
		} 
	}
	
} else {
	$color = "#ff0000";
}

$o .= '<a href="?page=monitoring&id='.$id.'"><i class="icon-plus"></i>monitoring</a><br>';

if ($kegiatan) {
	
	$o .= '
	<div class="row">
		<div class="span4">
			<table class="table table-striped">';
	
			$no = 1;
			
			foreach($kegiatan as $x) {
				
				$o .= '<tr>
							<td>Nama Kegiatan</td><td>: '.$x['nama_kegiatan'].'</td>
					  </tr>
					  <tr>
							<td>Kabupaten</td><td>: '.$x['kabupaten'].'</td>
					 </tr>
					 <tr>
							<td>Sektoral</td><td>: '.$x['sektoral'].'</td>
					</tr>
					<tr>
							<td>Pagu</td><td>: Rp. '.number_format($x['pagu']).'</td>
					</tr>
					<tr>
							<td>Longitude</td><td>: '.$x['long'].'</td>
					</tr>
					<tr>
							<td>Latitude</td><td>: '.$x['lat'].'</td>
					</tr>
					<tr>
							<td>Tahun</td><td>: '.$x['tahun'].'</td>
					</tr>
					<tr>
							<td>Operator</td><td>: '.$x['username'].'</td>
					</tr>
					';		
			}

			$o .= '</table>
			
			</div>';
			
			$js .= '
		<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
		<script type="text/javascript">
		 	var peta;';
		 	
		 	$str = $x['polygon'];
			$str = str_replace(" ","", $str);
			$str = str_replace(")(",") (", $str);
			$str = explode(" ", $str);

			for ($i=0;$i<count($str);$i++) {
				$cord .= "new google.maps.LatLng".$str[$i].",";
			}
			$cord = substr($cord,0,strlen($cord)-1);
			
			$js .= '
				 	
			
			var paths = ['.$cord.'];
			
			var gambar_tanda;
			
			gambar_tanda = "../file/icon/'.$x['icon'].'";
			
			function peta_awal(){
		    	var lokasibaru = new google.maps.LatLng('.$x['lat'].','.$x['long'].');
	    		var petaoption = {
	        	zoom: 13,
	        	center: lokasibaru,
	        	mapTypeId: google.maps.MapTypeId.ROADMAP
	        		
       		 };
       		 
       		 	peta = new google.maps.Map(document.getElementById("map_canvas"),petaoption);
	        	
		    
				poly = new google.maps.Polygon({
				paths: paths,
				strokeWeight: 0,
				fillColor: "'.$color.'",
				fillOpacity: 0.5
				});
			
				poly.setMap(peta);
				
				tanda = new google.maps.Marker({
					position: lokasibaru,
					icon: gambar_tanda,
					map: peta
				});
		    
		}
		</script>';

echo $js;

	$o .='
		 <div class="span8">
			<div id="map_canvas" style="height:300px"></div>
		
		  </div></div><br><br>';
	
	
	
	if ($image) {
	
		$o .= '
			<h2>progress</h2>
			<table class="table table-striped table-bordered table-condensed">
				<tr>
					<td><center>No</td>
					<td><center>Progress</td>
					<td><center>Foto</td>
					<td><center>Tanggal Monitoring</td>
					<td colspan="2"><center>Aksi</td>
				</tr>
		
			  ';
		
		$no = 1;
		
		foreach($image as $x) {
			
			$o .= '<tr>
						<td><center>'.$no.'</td>
						<td><center>'.$x['progres'].' %</td>
						<td><center><a data-toggle="modal" href="#myModal'.$no.'"><img src="../file/thumbnail/'.$x['foto'].'"></a></td>
						<td><center>'.$x['tgl_monitoring'].'</td>
						<td><center><a href="?page=editmonitoring&id='.$x['idmonitoring'].'"><i class="icon-edit"></i>ubah</a></td>
						<td><center><a href="?page=detailkegiatan&action='.$x['idmonitoring'].'"><i class="icon-remove"></i>hapus</a></td>
				  </tr>';	  
			
			$o .= ' <div id="myModal'.$no.'" class="modal hide fade">
            <div class="modal-header">
              <button class="close" data-dismiss="modal">&times;</button>
           		<img src="../file/'.$x['foto'].'">
             <div class="modal-footer">
            
            </div>
          </div>';
			
			$no++;
			
		}
	
		$o .= '</table>';
	
	} else {

		$o .= '<div class="alert alert-error">
			  <center>Data monitor kosong</center>
			  </div>';
	} 
	
} else {

	$o .= '<div class="alert alert-error">
		  <center>Data kosong</center>
		  </div>';
} 

echo $o;
